package com.freesky.provider.content.controller;

import com.freesky.common.enums.PanelPositionEnum;
import com.freesky.common.pojo.DataTablesResult;
import com.freesky.common.pojo.ZTreeNode;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.common.dao.entity.PanelContent;
import com.freesky.provider.content.service.ICommonService;
import com.freesky.provider.content.service.IHomePanelContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 17:51 2018/12/12
 * @description:
 */
@RestController
public class HomePanelContentController {
    @Autowired
    private IHomePanelContentService homePanelContentService;
    @Autowired
    private ICommonService commonService;

    @RequestMapping(value = "/home/panel/content/tree/list",method = RequestMethod.GET)
    public List<ZTreeNode> treeList(){
        return homePanelContentService.treeList();
    }

    @GetMapping(value = "/home/panel/content/list/{panelId}")
    public DataTablesResult list(@PathVariable("panelId") int panelId) {
        return homePanelContentService.list(panelId);
    }
    @PostMapping(value =   "/home/panel/content/add")
    public JSONResponse add(@RequestBody PanelContent panelContent) {
        return commonService.add(panelContent);
    }

    @DeleteMapping(value =   "/home/panel/content/del/{ids}")
    public JSONResponse delete(@PathVariable("ids") int[] ids){
        return homePanelContentService.delete(ids);
    }


    @PostMapping(value = "/home/panel/content/update")
    public JSONResponse update(@RequestBody PanelContent panelContent) {
        return homePanelContentService.update(panelContent);
    }


    /**
     * 前台首页内容展示
     * @return
     */
    @GetMapping(value = "/home/portal/content")
    public JSONResponse getHomeContent() {
       return homePanelContentService.getHomeContent();
    }

}
